package com.english.controller;

import com.english.controller.admin.AdminBaseController;
import com.english.entity.Lesson;
import com.english.entity.LessonLog;
import com.english.service.LessonService;
import com.english.utils.R;
import com.english.vo.LessonAdjustVO;
import com.english.vo.LessonUseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.english.mapper.UserMapper;

/**
 * 课时管理接口
 *
 * @author wlq
 * @since 2025-08-05
 */
@RestController
@RequestMapping("/api/lesson")
@CrossOrigin(origins = "*", allowCredentials = "false", maxAge = 3600)
public class LessonController extends AdminBaseController {

    @Autowired
    private LessonService lessonService;

    @Autowired
    private UserMapper userMapper;


    /**
     * 管理员使用学生课时
     *
     * @param token 管理员token
     * @param useVO 使用课时信息
     * @return 操作结果
     */
    @PostMapping("/use")
    public R<String> useLesson(
            @RequestHeader("Authorization") String token,
            @RequestBody LessonUseVO useVO) {
        try {
            Long adminId = getAdminId(token);
            boolean ok = lessonService.useLesson(
                useVO.getStudentId(),
                useVO.getHours(),
                useVO.getTitle(),
                useVO.getDescription(),
                adminId
            );
            return ok ? R.success("课时使用成功", null) : R.error("课时使用失败");
        } catch (RuntimeException e) {
            return R.error(e.getMessage());
        }
    }




}
